Ext.namespace("NewCustomer");

NewCustomer.ToImp = function() {
	this.winView = null;
	this.winImp = null;
	
	this.txtIssueTitle = new Ext.form.TextField({
		name : 'issueTitle',
		width: 150
	});
	this.storeType  = new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: [[1, '第三方平台终端缺货问题'],[2, '集采平台终端缺货问题'],[3, '终端设备类问题'],
        		[4, 'SIM卡类问题'],[5, '重点营销活动界面反映问题'],[6, '客户投诉及一线客户服务需求问题'],
        		[7, '生产运营设备情况'],[8, '后勤支撑'],[9, '员工队伍情况'],[10, '市场信息'],[11, '其他']]
    });
	this.txtIssueType = new Ext.form.ComboBox({
		width: 150,
		name:'issueType',
		store: this.storeType,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        selectOnFocus: true
	});
	this.dtStart = new Ext.form.DateField({
		width: 85,
		name : 'issueDateFm',
		format: 'Y-m-d'
	});
	this.dtEnd = new Ext.form.DateField({
		width: 85,
		name : 'issueDateTo',
		format: 'Y-m-d'
	});
	this.btnImp = new Ext.Toolbar.Button({
        iconCls: 'icon-newplan',
        text: '督办',
        tooltip: {text: '督办'},
        handler: this.onImpIssue,
        scope: this
    });
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找厅问题'},
        handler: this.queryIssue,
        scope: this
    });
		
	this.store = new Ext.data.JsonStore({
	    url: '../superviseIssue/toImpIssue.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['issueId','issueTitle','issueContent','issueType','deptId',
	    'issueStatus','createId','managerId','createTime','issueDate','instancyLevel','reportDept',
	    'superviseId','superviseType','importantFlag','superviseState','closeFlag',
	    'inspectorId','inspectorName','dispatchDate','feedback','fulfill','completeDate','notion',
	    'deptName','managerName','reportDeptName','createName','superviseTime']
	});
	//this.store.setDefaultSort('DocId', 'desc');
	this.renderType = function(value){
		return OMS.ISSUE_TYPE[value];
	};
	this.renderLevel = function(value){
		return OMS.ISSUE_LEVEL[value];
	};
	this.renderStatus = function(value){
		return OMS.ISSUE_STATUS[value];
	};
	this.column = [
		{header: '问题ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'issueId'},
		{header: '问题标题', sortable: true, align: 'center',width: 20,dataIndex: 'issueTitle'},
		{header: '营业厅ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'deptId'},
		{header: '营业厅', sortable: true, align: 'center',width: 20,dataIndex: 'deptName'},
		{header: '问题描述', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'issueContent'},
		{header: '问题类型', sortable: true, align: 'center',width: 20,dataIndex: 'issueType',renderer:this.renderType},		
		{header: '紧急程度', sortable: true, align: 'center',width: 20,dataIndex: 'instancyLevel',renderer:this.renderLevel},
		{header: '提出时间', sortable: true, align: 'right',width: 20,dataIndex: 'issueDate'},	
		{header: '填报人', sortable: true, align: 'center',width: 20,dataIndex: 'createName'},
		{header: '问题状态', sortable: true, align: 'center',width: 20,dataIndex: 'issueStatus',renderer:this.renderStatus},
		{header: '创建人ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'createId'},
		{header: '人员选择', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'managerId'},
		{header: '创建时间', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'createTime'},	
		{header: '部门选择', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'reportDept'},
		{header: '督办ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'superviseId'},
		{header: '督办类型', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'superviseType'},
		{header: '已转重要问题', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'importantFlag'},
		{header: '督办状态', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'superviseState'},
		{header: '归档标志', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'closeFlag'},	
		{header: '阅处人id', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'inspectorId'},
		{header: '阅处人名称', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'inspectorName'},
		{header: '选择人名称', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'managerName'},
		{header: '选择部门名称', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'reportDeptName'},	
		{header: '任务派发时间', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'dispatchDate'},
		{header: '反馈情况', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'feedback'},
		{header: '落实情况', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'fulfill'},
		{header: '督办时间', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'superviseTime'},
		{header: '完成时限', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'completeDate'},
		{header: '批示意见', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'notion'}
	];	
			
	NewCustomer.ToImp.superclass.constructor.call(this, {
		title: '待转督办厅问题',
        region: 'center',
        cm: new Ext.grid.ColumnModel(this.column),
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        tbar: [this.btnImp,'->','问题标题:', this.txtIssueTitle,'问题类型:', this.txtIssueType, 
		          '提问时间:', this.dtStart, '~', this.dtEnd,this.btnSearch],
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        store:this.store,
        viewConfig: { forceFit: true },
        listeners:{
        	rowdblclick : this.onViewIssue,
			//render:this.queryIssue
			activate: this.queryIssue
		}
    });
};
Ext.extend(NewCustomer.ToImp, Ext.grid.GridPanel, {
	queryIssue:function(btn,event){
		var param={
			start : 0,
			limit : 15,
			issueDateFm:this.dtStart.getValue(),
			issueDateTo:this.dtEnd.getValue(),
			issueTitle:this.txtIssueTitle.getValue(),
			issueType:this.txtIssueType.getValue()
		};
		this.store.load({
			params:param
		});
	},
	onImpIssue: function(btn, event) {		
		if (this.winImp == null) {
			this.winImp = new NewCustomer.Imp(this);
		}
		var records = this.getSelectionModel().getSelections();
		if(records.length==0){
			Utils.warn2('请选择一条厅问题！',180);
			return ;
		}else if(records.length>1){
			Utils.warn2('只能选择一条厅问题！',180);
			return;
		}
		this.winImp.show();
		this.winImp.initWin(records[0].data);		
	},
	onViewIssue:function(grid, rowIndex,e){		
		if (this.winView == null) {
			this.winView = new NewCustomer.View(this);
		}
		this.winView.show();
		this.winView.initWin(grid.store.getAt(rowIndex).data);		
	}
});
